#ifndef CAR_H
#define CAR_H
#include<vector>

#include<string>

struct Tire;//轮胎

struct Chassis;//底盘

struct AGXXKit;//AGX套件

struct StereoCamera;//双目摄像头

struct LiDAR;//多线激光雷达

struct Gyroscope;//9轴陀螺仪

struct LCDScreen;//液晶显示屏

struct Bettery;//电池

struct Student;


//轮胎
struct Tire{
    std::string type;//型号
    std::string size;//尺寸
};
//序列化
std::ostream& operator<<(std::ostream& os,const Tire& tire);
std::istream& operator>>(std::istream& is,Tire& tire);

//底盘
struct Chassis{
    std::string id;//编号
    std::string model;//型号
    std::string wheelbase;//轴距
    std::string trackWidth;//轮距
    std::string minGroundClear;//最小离地间隙
    std::string minTurnRadius;//最小转弯半径
    std::string driveType;//驱动类型
    std::string maxRange;//最大行程
    Tire tires[4];//四个轮胎
};

std::ostream& operator<<(std::ostream& os,const Chassis& chassis);
std::istream& operator>>(std::istream& is,Chassis& chassis);

//AGX套件
struct AGXKit{
    std::string model;//型号
    std::string aiPerformance;//AI性能
    std::string cudaCores;//CUDA核心
    std::string tensorCores;//Tensor核心
    std::string vram;//显存
    std::string storage;//储存
};
std::ostream& operator<<(std::ostream& os,const AGXKit& agxKit);
std::istream& operator>>(std::istream& is,AGXKit& AGXKit);


//双目摄像头
struct StereoCamera{
    std::string model;//型号
    std::string camModule;//摄像头
    std::string rgbRes;//RGB分辨率
    std::string rgbFps;//RGB帧率
    std::string fov;//FOV视场角
    std::string depthFps;//深度帧率
};
std::ostream& operator<<(std::ostream& os, const StereoCamera& stereoCam);
std::istream& operator>>(std::istream& is, StereoCamera& stereoCam);


//多线激光雷达
struct LiDAR{
    std::string model;//型号
    std::string lines;//通道数
    std::string testRange;//测试范围
    std::string power;//功耗
};
std::ostream& operator<<(std::ostream& os, const LiDAR& lidar);
std::istream& operator>>(std::istream& is, LiDAR& lidar);

//9轴陀螺仪
struct Gyroscope{
    std::string model;//型号
    std::string manufacturer;//厂家
};
std::ostream& operator<<(std::ostream& os, const Gyroscope& gyro);
std::istream& operator>>(std::istream& is, Gyroscope& gyro);

//液晶显示屏
struct LCDScreen{
    std::string size;//尺寸
    std::string model;//型号
};
std::ostream& operator<<(std::ostream& os, const LCDScreen& lcd);
std::istream& operator>>(std::istream& is, LCDScreen& lcd);


//电源
struct Bettery{
    std::string params;//参数
    std::string outputVolt;//对外供电
    std::string chargeTime;//充电时间
};
std::ostream& operator<<(std::ostream& os, const Bettery& battery);
std::istream& operator>>(std::istream& is, Bettery& battery);

//学生
struct Student{
    std::string id;//学号
    std::string name;//姓名
};
std::ostream& operator<<(std::ostream& os, const Student& student);
std::istream& operator>>(std::istream& is, Student& student);


//小车类
class Car{
private:
    std::string carId;//小车编号
    Chassis chassis;//底盘
    AGXKit agxKit;//AGX套件
    StereoCamera stereoCamera;//双目摄像头
    LiDAR lidar;//多线激光雷达
    Gyroscope gyroscope;//9轴陀螺仪
    LCDScreen lcdScreen;//液晶显示屏
    Bettery bettery;//电池
    Student student;//学生
    bool isAssignedStudent=false;//是否分配学生

    void initDefaultComponents();//默认初始化小车信息
public:
    Car();//无参构造
    Car(const std::string& carId);//带参构造（灵活）

    //小车信息录入接口
    void setCarId(const std::string& carId);
    void assignStudent(const Student& student);//分配学生
    void setChassis(const Chassis& chassis);//设置底盘
    void setAGXKit(const AGXKit& agxXKit);//设置AGX套件
    void setStereoCamera(const StereoCamera& stereoCamera);//设置双目摄像头
    void setLiDAR(const LiDAR& lidar);//设置多线激光雷达
    void setGyroscope(const Gyroscope& gyroscope);//设置9轴陀螺仪
    void setLCDScreen(const LCDScreen& lcdScreen);//设置液晶显示屏
    void setBattery(const Bettery& bettery);//设置电池
    
    bool getIsAssignedStudent() const;
    std::string getCarId();
    Student getStudent();
    Chassis getChassis();
    AGXKit getAGXKit();
    StereoCamera getStereoCamera();
    LiDAR getLiDAR();
    Gyroscope getGyroscope();
    LCDScreen getLCDScreen();
    Bettery getBettery();
    //小车信息显示接口
    void displayCarInfo();

    // void serialize(std::ostream& os) const;//序列化小车信息

    // 序列化/反序列化接口（成员函数）
    void serialize(std::ostream& os) const;// 写入对象到流
    void deserialize(std::istream& is);   // 从流读取对象

    static bool saveCarsToFile(const std::vector<Car>& cars, const std::string& filename);
    static bool loadCarsFromFile(std::vector<Car>& cars, const std::string& filename);
    // 静态接口：vector<Car> 读写文件（核心功能）
    
};


#endif // CAR_H